/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       image.h
 * Author:     karooolek
 * Created on: 2009-03-22
 *
 **********************************************************************************************************************/

#ifndef IMAGE_H_
#define IMAGE_H_

#include "../common.h"

namespace mGameEngine
{
namespace Graphics
{

/**
 * Image resource.
 * Structure for storing images in memory.
 * Image size is limited only by system.
 * Lower left corner of image is at 0, 0 coorinates.
 */
class Image
{
protected:
    /**
     * Image data buffer
     */
    uint8 *_data;

    /**
     * Image width
     */
    uint _width;

    /**
     * Image height
     */
    uint _height;

    /**
     * Bits per image pixel
     */
    uint8 _bpp;

public:
    /**
     * Create empty image.
     */
    Image();

    /**
     * Create image from data buffer.
     * @param data data buffer
     * @param width image width
     * @param height image height
     * @param bpp bits per image pixel
     */
    Image(const uint8 *data, uint width, uint height, uint8 bpp);

    /**
     * Destroy image.
     */
    virtual ~Image();

    /**
     * Get image data buffer.
     * @return image data buffer
     */
    const uint8* getData() const
    {
        return _data;
    }

    /**
     * Set image data.
     * @param data data buffer
     * @param width image width
     * @param height image height
     * @param bpp bits per image pixel
     */
    void setData(const uint8 *data, uint width, uint height, uint8 bpp);

    /**
     * Get image width.
     * @return image width
     */
    uint getWidth() const
    {
        return _width;
    }

    /**
     * Get image height.
     * @return image height.
     */
    uint getHeight() const
    {
        return _height;
    }

    /**
     * Get bits per image pixel.
     * @return bits per image pixel.
     */
    uint8 getBitsPerPixel() const
    {
        return _bpp;
    }

    /**
     * Get specified pixel color.
     * @param x pixel X coordinate.
     * @param y pixel Y coordinate.
     * return specified pixel color.
     */
    virtual Color getColorAt(uint x, uint y) const;

    /**
     * Set specified pixel color.
     * @param color color to set.
     * @param x pixel X coordinate.
     * @param y pixel Y coordinate.
     */
    virtual void setColorAt(const Color &color, uint x, uint y);

    /**
     * Get specified pixel data.
     * @param x pixel X coordinate.
     * @param y pixel Y coordinate.
     * @return specified pixel data or NULL when pixel is not in image.
     */
    virtual const uint8 *getDataAt(uint x, uint y) const;

    /**
     * Set specified pixel data.
     * @param data pixel data to set.
     * @param x pixel X coordinate.
     * @param y pixel Y coordinate.
     */
    virtual void setDataAt(const uint8 *data, uint x, uint y);

};

}
}

#endif // IMAGE_H_
